package com.ruoyi.system.mapper.wlwsys;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.common.core.domain.entity.WlwsysDevice;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
* @author 86187
* @description 针对表【wlwsys_device】的数据库操作Mapper
* @createDate 2023-07-19 17:34:42
* @Entity com.ruoyi.domain.entity.WlwsysDevice
*/
@Mapper
public interface WlwsysDeviceMapper extends BaseMapper<WlwsysDevice> {
    //查询所有没有逻辑删除的所有数据
    @Select("select * from wlwsys_device where is_delete != 1 ")
    @Results(value = {
            @Result(column = "device_id",property = "deviceId"),
            @Result(column = "device_name",property = "deviceName"),
            @Result(column = "device_introduce",property = "deviceIntroduce"),
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    public List<WlwsysDevice> selectAll();


    //分页查询，没有时间区间
    @Select("select * from wlwsys_device " +
            "where device_id like concat('%',#{deviceId},'%') " +
            "and device_name like concat('%',#{deviceName},'%') and project_id like concat('%',#{projectId},'%') and is_delete != 1 order by create_time desc")
    @Results(value = {
            @Result(column = "device_id",property = "deviceId"),
            @Result(column = "device_name",property = "deviceName"),
            @Result(column = "device_introduce",property = "deviceIntroduce"),
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    public List<WlwsysDevice> selectDevice(@Param("deviceId")String deviceId, @Param("deviceName")String deviceName,
                                           @Param("projectId")String projectId);

    //分页查询，有时间区间
    @Select("select * from wlwsys_device " +
            "where device_id like concat('%',#{deviceId},'%') " +
            "and device_name like concat('%',#{deviceName},'%') and project_id like concat('%',#{projectId},'%')" +
            "and #{startTime}<=create_time and #{endTime}>=create_time and is_delete != 1 order by create_time desc")
    @Results(value = {
            @Result(column = "device_id",property = "deviceId"),
            @Result(column = "device_name",property = "deviceName"),
            @Result(column = "device_introduce",property = "deviceIntroduce"),
            @Result(column = "project_id",property = "projectId"),
            @Result(column = "create_time",property = "createTime"),
            @Result(column = "update_time",property = "updateTime"),
            @Result(column = "is_delete",property = "isDelete"),
    })
    public List<WlwsysDevice> selectDeviceHaveTime(@Param("deviceId")String deviceId, @Param("deviceName")String deviceName,
                                                   @Param("projectId")String projectId, @Param("startTime")String startTime,
                                                   @Param("endTime")String endTime);

    @Update("update wlwsys_device set is_delete=true where device_id=#{deviceId}")
    public void deleteByDeviceId(@Param("deviceId") String deviceId);

    @Insert("insert into wlwsys_device values(#{deviceId},#{deviceName},#{deviceIntroduce},#{projectId},#{updateTime},#{updateTime},0)")
    public void insertNew(@Param("deviceId")String deviceId, @Param("deviceName")String deviceName, @Param("deviceIntroduce")String deviceIntroduce,
                          @Param("projectId")String projectId, @Param("updateTime")String updateTime);

    @Update("update wlwsys_device set device_name=#{deviceName},device_introduce=#{deviceIntroduce},project_id=#{projectId},update_time=#{updateTime} where device_id=#{deviceId}")
    public boolean updateByDeviceId(@Param("deviceId")String deviceId, @Param("deviceName")String deviceName, @Param("deviceIntroduce")String deviceIntroduce,
                                            @Param("projectId")String projectId, @Param("updateTime")String updateTime);


}




